@isTest
private class DealerOppControllerTest {

    static testMethod void testMethod1() {
        	
        /* Country__c country = TestUtils.createCountry();
        country.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('OldCountryArchive','Country__c');
        insert country;

        // CharacteristicMedicalMarket__c  cmm = TestUtils.createCharacteristicMedicalMarket();
        // cmm.Country__c = country.Id;
        // insert cmm;

        MedicalGrade__c medicalgrade = TestUtils.createMedicalGrade();
        medicalgrade.Country__c = country.Id;
        insert medicalgrade;

        IVDWholeMarket__c ivdwm = TestUtils.createIVDWholeMarket();
        ivdwm.Country__c = country.Id; 

        IVDProductLineMarket__c ivdplm = TestUtils.createIVDProductLineMarket();
        ivdplm.Country__c = country.Id;
        insert ivdplm;


        Province__c province = TestUtils.createProvince();
        insert province;

        City__c city = TestUtils.createCity();
        city.Province__c = province.Id;
        insert city;

        District__c district = TestUtils.createDistrict();
        district.City__c = city.Id;
        insert district;*/
         Account acc1 = TestUtils.createAccount();
        acc1.Name = '客户B';
        acc1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('Dealer','Account');
        insert acc1 ; 

      Account acc = TestUtils.createAccount();
        acc.Name = '客户A';
        acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('TerminalCustomer','Account');
        //acc.Country__c = country.Id;
       // acc.District__c = district.Id;
        //acc.Province__c = province.Id;
        //acc.City__c = city.Id;
        //acc.SpecialDepart__c = '内科_呼吸内科; 内科_神经内科';
        //acc.CustomerAttribute__c = '公立医疗机构';
        //acc.Level__c = '一级医院';
        insert acc;
  /*
        Department__c dt1=[select id,hospitalDepartments__c,TerminalCustomer__c from Department__c where 
        hospitalDepartments__c='检验科' and TerminalCustomer__c=:acc.Id limit 1];
        dt1.LastYearRevenue__c=123;
        update dt1;*/

        //Opportunity opp = TestUtils.createOpportunity();
        //opp.Name = '业务机会A';
        //opp.AccountId = acc.Id;
        //opp.StageName = '意向';
        //opp.Department__c = '检验科';
        //opp.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('CustomerOpportunity','Opportunity');
        //insert opp;


        Opportunity opp = TestUtils.createOpportunity();
        opp.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('DealerOpportunity', 'Opportunity');
        opp.AccountId = acc1.Id;
        opp.StageCanChange__c = '意向';
        opp.StageName = '意向';
        insert opp;
        PageReference page = new PageReference('/apex/DealerOpp?id=' + opp.Id);
        System.Test.setCurrentPage(page);

        DealerOppController dopp = new DealerOppController();
      
        //dopp.backId =  ;
        dopp.init();
         page = new PageReference('/apex/DealerOpp?id=' + acc1.Id);
        System.Test.setCurrentPage(page);
        dopp = new DealerOppController();
        dopp.init();
        Map<String,String> searchMap = new Map<String,String>();
        searchMap.put('accName', '客户');
        dopp.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap), 'UTF-8');
        dopp.search();
        Map<String,Object> saveMap = new Map<String,Object>();

        Map<String,String> DealerMap = new Map<String,String>();

        DealerMap.put('accId', acc1.Id);
        DealerMap.put('registerAmount', '100');

        List<Object>AccountList = new  List<Object>();

        Map<String,String> AccountMap = new Map<String,String>();
        AccountMap.put('accId', acc.Id);
        AccountList.add(AccountMap);

        List<Object>ProductList = new  List<Object>();

        Map<String,String> ProductMap = new Map<String,String>();
        ProductMap.put('agentProductLine', '生化');
        ProductList.add(ProductMap);

        saveMap.put('Dealer', DealerMap);
        saveMap.put('Account', AccountList);
        saveMap.put('Product', ProductList);

        dopp.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap), 'UTF-8');
        dopp.save();

        page = new PageReference('/apex/DealerOpp?id=' +  opp.Id+'&drop=true');
        System.Test.setCurrentPage(page);
        dopp = new DealerOppController();
        dopp.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap), 'UTF-8');
        dopp.save();


        OpportunityWebService.checkOpp(opp.id);


    }
}